package sia.erp.connections;

import java.io.IOException;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.xmlpull.v1.XmlPullParserException;

import sia.erp.venta_ruta.R;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;

public class WebServiceExecute extends AsyncTask<Object, Integer, Void>{
	private final static String NAMESPACE = "http://tempuri.org/";

	@Override
	protected Void doInBackground(Object... args) {
		String method_name = (String) args[0];
		Context context = (Context) args[1];
		SoapObject request = new SoapObject(NAMESPACE, method_name);

		String soap_action = NAMESPACE + method_name;
		
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		
		
		envelope.dotNet = true;
		envelope.implicitTypes = true;
		envelope.encodingStyle = SoapSerializationEnvelope.XSD;
		envelope.setOutputSoapObject(request);
		
		MarshalDouble md = new MarshalDouble();
		md.register(envelope);

		
		HttpTransportSE androidHttp = new HttpTransportSE(context.getString(R.string.web_service_reference));

		for(int i = 2; i < args.length; i++)
			request.addProperty((PropertyInfo)args[i]);
		try {
			androidHttp.call(soap_action, envelope);
		} catch (IOException e) {
			Log.e("There was an IO exception @makeRequest", e.getMessage());
		} catch (XmlPullParserException e) {
			Log.e("There was a XML parser exception @makeRequest", e.getMessage());
		}
		return null;

	}
}
